﻿{include file=header.html}
<script language="javascript" type="text/javascript" src="{res file=DatePicker/WdatePicker.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/jquery-1.2.6.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/jquery.funkyUI.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/common.js}"></script>
<script language="javascript" type="text/javascript" src="{lib file=jquery.plugins/jquery.validate.js}"></script>
<script type="text/javascript">
$(function(){
$('#sample_form').validate({
onkeyup : false,
onfocusout : false,
rules : {
arrival_date: {
required: true,
dateISO: true
},
brand_id: {
min: 1
},
buyer_id: {
min: 1
},
merchandiser_id: {
min: 1
},
sample_sn: {
required: true
},
ref_sample_style:{
min: 1
}
},
messages : {
arrival_date: {
required: '<br>{$lang.arrival_date_not_empty}',
dateISO: '<br>{$lang.date_format_error}'
},
brand_id: {
min: '<br>{$lang.brand_select_pls}'
},
buyer_id: {
min: '<br>{$lang.buyer_select_pls}'
},
merchandiser_id: {
min: '<br>{$lang.merch_select_pls}'
},
sample_sn: {
required: '<br>{$lang.sample_sn_not_empty}'
},
ref_sample_style: {
min: '<br>{$lang.ref_sample_style_select_pls}'
}
}
});
$('#check_all').click(function() {
check_all();
});
$('input[name="sample_id"]').click(function() {
if (!$(this).attr('checked')) {
$('#check_all').attr('checked', false);
} else {
var flag = true;
$('input[name="sample_id"]').each(function(i) {
if (!$(this).attr('checked')) {
flag = false;
return;
}
});
$('#check_all').attr('checked', flag);
}
});
$('#more_reset').click(function() {
if ($('input[name="sample_id"]:checked').length < 1) {
alert('{$lang.select_reseted_sample_please}');
} else {
var sample_ids = '';
$('input[name="sample_id"]:checked').each(function(i) {
sample_ids += $(this).val() + ',';
});
sample_ids = sample_ids.substr(0, sample_ids.length - 1);
location.href = 'index.php?app=sample&act=more_reset&ids=' + sample_ids;
}
});

$("#brand_id_search").change(function(){
var url="index.php?app=sample&act=ajax_get_buyer&id="+$(this).val();
$.getJSON(url,function(ret){
if(ret)
{
$("#buyer_id_search option").remove();
$("#buyer_id_search").append('<option value="0"></option>');
for(i in ret)
{
$("#buyer_id_search").append('<option value="'+ret[i]['user_id']+'" >'+ret[i]['user_name']+'</option>');
}
}
});


});
});

function edit(obj, id)
{
location.href="index.php?app=sample&act=edit&id="+id;
return;
var row = obj.parentNode.parentNode;
var data = row.getElementsByTagName('td');
$('#arrival_date').val(data[2].innerHTML);
$('#brand_id').val(data[3].getElementsByTagName('input')[0].value);
brand_change($('#brand_id').val(), data[4].getElementsByTagName('input')[0].value, data[5].getElementsByTagName('input')[0].value);
$('#sample_sn').val(data[6].firstChild.innerHTML);
$('#order_sn').val(data[10].innerHTML);
$('#ref_sample_style').val(data[7].getElementsByTagName('input')[0].value);
$("#sample_customer_filesize .upload_btn").attr("disabled","disabled");
$("#sample_customer_filesize *:not(.upload_btn)").hide();
$('#submit').val('{$lang.update}');
$('#cancel').remove();
$('#submit').parent().append('<input type="button" id="cancel" class="btn-1" value="{$lang.cancel}" onclick="cancel_edit();" />');
$('#sample_form').attr({'action':'index.php?app=sample&act=modify&id=' + id});
}

function cancel_edit()
{
$('#arrival_date').val('{$new_arrival_date|date:Y-m-d}');
$('#brand_id').val(0);
brand_change($('#brand_id').val());
$('#sample_sn').val('');
$('#ref_sample_style').val(0);
$("#sample_customer_filesize .upload_btn").attr("disabled","");
$("#sample_customer_filesize *:not(.upload_btn)").show();

$('#submit').val('{$lang.add}');
$('#sample_form').attr({'action':'index.php?app=sample&act=add'});
$('#cancel').remove();
}

function check_all()
{
if ($('#check_all').attr('checked')) {
$('input[name="sample_id"]').attr('checked', true);
} else {
$('input[name="sample_id"]').attr('checked', false);
}
}


function add_customer_file(obj) {
var parent = obj.parentNode;
var span = document.createElement('span');
span.innerHTML = '<input type="file" name="customer_reviews[]" class="input-2" hidefocus="true" />';
parent.insertBefore(span, obj);
}
function remove_customer_file(obj) {
var parent = obj.parentNode.parentNode;
parent.removeChild(obj.parentNode);
}
</script>
<style>
label.error { color: #FF0000; }
</style>
<body>
<div class="sub-body">
	<form method="get" action="{url app=sample}" id="search_form">
		<input type="hidden" name="app" value="sample" />
		<table cellspacing="0" cellpadding="0" class="search" width="80%">
			<tr>
				<th width="100">{$lang.merchandiser}：</th>
				<td width="200"><select {if $user.role eq USER_MERCHANDISER} disabled{/if} name="merchandiser">
						<option value="0"></option>
						<!--{foreach from=$merchandiser_list item=merchandiser}-->
						<option value="{$merchandiser.user_id}"{if $merchandiser.user_id == $user.user_id} selected{/if}>{$merchandiser.user_name}</option>
						<!--{/foreach}-->
					</select></td>
				<th width="100">品牌：</th>
				<td width="200"><select name="brand_id" id="brand_id_search">
						<option value="0"></option>
						<!--{foreach from=$brand_list item=brand}-->
						<option value="{$brand.brand_id}" {if $brand.brand_id == $smarty.get.brand_id}selected{/if}>{$brand.brand_name|escape}&nbsp;&nbsp;({$brand.company_name|escape})</option>
						<!--{/foreach}-->
					</select></td>
				<th width="100">{$lang.buyer_name}：</th>
				<td width="200"><select name="buyer" id="buyer_id_search">
						<option value="0"></option>
						<!--{foreach from=$buyer_list item=buyer}-->
						<option value="{$buyer.user_id}"{if $buyer.user_id == $smarty.get.buyer} selected{/if}>{$buyer.user_name}</option>
						<!--{/foreach}-->
					</select></td>
				<td width="100" rowspan="2"><input name="search" type="submit" class="inquiry" value="{$lang.search}"/></td>
			</tr>
			<tr>
				<th>{$lang.sample_sn}：</th>
				<td><input type="text" name="sample_sn" class="input-1" value="{if $sample_sn}{$sample_sn}{/if}" /></td>
				<th>{$lang.arrival_date}：</th>
				<td><input type="text" name="arrival_date_start" class="input-6"  onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="{$smarty.get.arrival_date_start}" />
					{$lang.to_day}
					<input type="text" name="arrival_date_end" class="input-6"  onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="{$smarty.get.arrival_date_end}" /></td>
				<th></th>
				<td></td>
			</tr>
		</table>
	</form>
	<div class="tab_info">
		<h3 class="tab-title-1"><span>{$lang.sample_add}</span></h3>
		<form method="post" action="{url app=sample&act=add}" id="sample_form">
			<table width="100%" cellspacing="0" cellpadding="0" class="tab-display" id="tab-color1">
				<tr>
					<th width="3%">{$lang.No}</th>
					<th width="9%">{$lang.arrival_date}</th>
					<th width="9%">{$lang.brand_name}</th>
					<th width="11%">{$lang.buyer_name}</th>
					<th width="9%">{$lang.merchandiser}</th>
					<th width="6%">{$lang.sample_sn}</th>
					<th width="9%">{$lang.ref_sample_style}</th>
					<th width="7%">{$lang.pics}</th>
					<th width="7%">{$lang.customer_reviews}</th>
					<th width="9%">{$lang.order_sn}</th>
					<th nowrap="nowrap">{$lang.handle}</th>
				</tr>
				<tr>
					<td></td>
					<td><input type="text" name="arrival_date" id="arrival_date" class="input-8"  onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value=""/></td>
					<td><select class="input-8" name="brand_id" id="brand_id" onChange="brand_change(this.value);">
							<option value="0">{$lang.select_pls}</option>
							<!--{foreach from=$brand_list item=brand key=k}-->
							<option value="{$brand.brand_id}">{$brand.brand_name}&nbsp;&nbsp;({$brand.company_name|escape})</option>
							<!--{/foreach}-->
						</select></td>
					<td><select class="input-8" name="buyer_id" id="buyer_id" onChange="buyer_change(this.value);">
							<option value="0">{$lang.select_pls}</option>
							<!--{foreach from=$buyer_list item=buyer}-->
							<option value="{$buyer.user_id}">{$buyer.user_name}</option>
							<!--{/foreach}-->
						</select></td>
					<td><select class="input-8" name="merchandiser_id" id="merchandiser_id">
							<option value="0">{$lang.select_pls}</option>
							<!--{foreach from=$merchandiser_list item=merchandiser}-->
							<option value="{$merchandiser.user_id}">{$merchandiser.user_name}</option>
							<!--{/foreach}-->
						</select></td>
					<td><input type="text" name="sample_sn" id="sample_sn" class="input-8" /></td>
					<td><select class="input-8" name="ref_sample_style" id="ref_sample_style">
							<option value="0">{$lang.select_pls}</option>
							<!--{foreach from=$lang.ref_sample_styles item=item key=k}-->
							<option value="{$k}">{$item}</option>
							<!--{/foreach}-->
						</select></td>
					<td><input type="button" id="upload_pics" class="btn-3" value="{$lang.upload_pics}" onClick="block()"/>
						<input type="hidden" id="front_pic" name="front_pic" value="" />
						<input type="hidden" id="front_pic_small" name="front_pic_small" value="" />
						<input type="hidden" id="other_pic" name="other_pic" value="" /></td>
					<td id="sample_customer_filesize"><input type="button" class="btn-3 upload_btn" value="{$lang.upload_enclosure}"  onClick="upload_docs({$belongs_sample_customer_reviews}, {$default_customer_key_id});" />
						
						<!--{foreach from=$customer_reviews_files item=file}-->
						
						<input type="hidden" name="customer_files_id[]" value="{$file.file_id}" />
						<span><a href="download.php?id={$file.file_id}">{$file.file_name}</a><a class="pic_del" href="{url app=comupload&act=delete&id=$file.file_id}" onClick="return confirm('{$lang.confirm_del_file}')" title="{$lang.delete}">&nbsp;</a></span><!--{if !$smarty.foreach.last}-->
						<!--{/if}--> 
						<!--{/foreach}--></td>
					<td><input type="text" name="order_sn" id="order_sn" class="input-8"></td>
					<td><input type="hidden" value="{$return_url}" name="modify_return_url" />
						<input type="submit" id="submit" class="btn-1" value="{$lang.add}" /></td>
				</tr>
				<!--{foreach from=$sample_list item=sample name=sm}-->
				<tr>
					<td>{$smarty.foreach.sm.iteration}</td>
					<td>{$sample.arrival_date|date:Y-m-d}</td>
					<td>{$sample.brand_name|escape}
						<input type="hidden" value="{$sample.brand_id|escape}" /></td>
					<td>{$sample.member_name|escape}
						<input type="hidden" value="{$sample.buyer_id|escape}" /></td>
					<td>{$sample.user_name|escape}
						<input type="hidden" value="{$sample.merchandiser_id|escape}" /></td>
					<td><a href="{url app=sample&act=show&id=$sample.sample_id}">{$sample.sample_sn|escape}</a></td>
					<td>{$lang.ref_sample_styles.$sample.ref_sample_style}
						<input type="hidden" value="{$sample.ref_sample_style|escape}" /></td>
					<td  style="margin:0; padding:0;"><div class="tab-pic" ><!--{if $sample.front_pic}--><a href="{$site_url}/{$sample.front_pic|escape}" target="_blank"><img src="{$site_url}/{$sample.front_pic|escape}" alt="{$lang.click_to_show_big_front_pic}" title="{$lang.click_to_show_big_front_pic}"  style="border:none;width:80px; height:80px;" /></a><!--{/if}--></div></td>
					<td>&nbsp;</td>
					<td>{$sample.order_sn|escape}</td>
					<td><!--{if $sample.status == 0}-->
						
						<input type="button" class="btn-1" value="{$lang.modify}" onClick="edit(this, {$sample.sample_id});" />
						<input type="button" class="btn-1" value="{$lang.delete}" onClick="if(confirm('{$lang.confirm_delete_sample}')){location.href='{url app=sample&act=delete&id=$sample.sample_id}'}" />
						
						<!--{/if}--> 
						<!--{if $sample.status == 6 AND $user.role neq USER_MERCHANDISER}-->
						
						<input type="button" class="btn-1" value="{$lang.stock}" onClick="if(confirm('{$lang.confirm_stock_sample}')){location.href='{url app=sample&act=stock&id=$sample.sample_id}'}" />
						
						<!--{/if}--> 
						<!--{if $sample.status != 7 && $sample.status != 0}-->
						
						<input type="button" class="btn-1" value="{$lang.reset}" onClick="if(confirm('{$lang.confirm_reset_sample}')){location.href='{url app=sample&act=re_set&id=$sample.sample_id}'}" />
						
						<!--{/if}--></td>
				</tr>
				<!--{/foreach}--> 
			</table>
		</form>
	</div>
	{include file=page.html} </div>
<script language="javascript" type="text/javascript" src="{res file=js/tab_color.js}"></script>
</body>
</html>